<script type="text/javascript">
$(document).ready(function() {
    var initial_width;
    $('#isolation_table').jqGrid({
        url: '/access_control/grid',
        styleUI: 'Bootstrap',
        datatype: 'json',
        mtype: 'POST',
        colNames: ['编号', "[['label name'|translate]]", 'IP', 'initiator', "[['label volume'|translate]]", "[['label owner'|translate]]", "[['label Creation time'|translate]]", "操作"],
        colModel: [{
            name: 'id',
            index: 'id',
            width: 6,
            align: '',
            hidden: true
        }, {
            name: 'name',
            index: 'name',
            width: 8,
            align: 'left',
            formatter: function(cellvalue, option, row) {
            var outerWidth = $('#isolation_table_name').width() - 20;
            return '<a style="display:inline-block;text-overflow:ellipsis; white-space:nowrap;overflow:hidden;width:' + outerWidth + 'px;" href="#" onclick="detail_open(\'' + option.gid + '\',\'' + option.rowId + '\')">' + cellvalue + '</a>';
        },
        unformat: function(cellvalue) {
            return cellvalue;
        }
        }, {
            name: 'iprange',
            index: 'iprange',
            width: 13,
            align: 'left',
            formatter: function(cellvalue, option, row) {
            var outerWidth = $('#isolation_table_name').width() - 20;
            return '<span style="display:inline-block;text-overflow:ellipsis; white-space:nowrap;overflow:hidden;width:' + outerWidth + 'px;" href="#">' + cellvalue + '</span>';
        },
        unformat: function(cellvalue) {
            return cellvalue;
        }
        }, {
            name: 'initiator',
            index: 'initiator',
            width: 13,
            align: 'left',
            formatter: function(cellvalue, option, row) {
            var outerWidth = $('#isolation_table_name').width() - 20;
            return '<span style="display:inline-block;text-overflow:ellipsis; white-space:nowrap;overflow:hidden;width:' + outerWidth + 'px;" href="#">' + cellvalue + '</span>';
        },
        unformat: function(cellvalue) {
            return cellvalue;
        }
        }, {
            name: 'volume_len',
            index: 'volume_len',
            width: 5,
            align: 'left',
            sortable: false
        }, {
            name: 'username',
            index: 'username',
            width: 6,
            align: 'left'
        }, {
            name: 'created_at',
            index: 'created_at',
            width: 8,
            align: 'left'
        }, {
            name: 'created_at',
            index: 'created_at',
            width: 7,
            align: 'left',
            detailHidden: true,
            formatter: function(cell, option, row) {
                var html = '';
                html += '<button title="编辑" controller="IsolationModalCtrl"  class="btn btn-blue btn-sm" onclick=dialog_policy_update(' + row[0] + ')>编辑</button>';
                html += '<button title="删除" style="margin-left:10px;" class="btn btn-blue btn-sm" onclick=confirm_policy_delete(' + row[0] + ',"' + row[1] + '")>删除</button>';
                return html;
            }
        }],
        page: 1,
        rowNum: 10,
        sortname: 'id',
        sortorder: 'desc',
        viewrecords: true,
        multiselectWidth: 40,
        altclass: 'ui-priority-secondary',
        altRows: true,
        autowidth: true,
        multiselect: false,
        multiboxonly:true,
        multiselectWidth:'60px',
        gridComplete: function() {
            var gridData = $(this).jqGrid('getRowData');
            jqgrid_page($(this), gridData);
            jqgrid_resize($(this));
        }
    });


    $("#accessPolicyButton").click(function() {
        angular.element('#accessPolicyButton').scope().open("/access_control/create");
    });
});

function policy_delete(policy_id) {
    $.ajax({
        url: "/access_control/delete",
        type: "POST",
        dataType: "json",
        data: {
            'id': policy_id
        },
        success: function(data) {
            if (data.reply.is_success) {
                $("#isolation_table").trigger("reloadGrid");
            } else {
                error = data.reply.error;
                SelfAlert(error);
            }
        }
    });
}

function confirm_policy_delete(policy_id, policy_name) {
    msg = '确定删除访问策略（' + policy_name + '）？';
    SelfConfirm(msg, policy_delete, policy_id, "删除提示");
}

function dialog_policy_update(policy_id) {
    angular.element('#accessPolicyButton').scope().open('/access_control/update?id=' + policy_id);

}
</script>
<div class="panel panel-f-style">
    <div class="panel-body">
        <div class="title-tag">
            <h3>访问策略</h3>
            <p>访问策略管理</p>
        </div>
        <div class="grid-tools">
            <div class="grid-operate pull-left">
                <button class="btn btn-blue" type="button" id="accessPolicyButton" ng-controller="IsolationModalCtrl">[['button create'|translate]]</button>
                <!-- <button class="btn btn-blue" type="button" controller="IsolationModalCtrl" onclick=dialog_policy_update()>编辑</button>
                <button class="btn btn-blue" type="button" onclick=confirm_policy_delete()>删除</button> -->
            </div>
        </div>
        <div class="grid-body" id="gridttt">
            <table id="isolation_table"></table>
        </div>
    </div>
</div>
